<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Array</title>
</head>
<body>
<script>
    //求和
    Array.prototype.sum = function () {
        for (var sum = i = 0;i<this.length;i++){
            sum+=parseInt(this[i]);
        }
        return sum;
    }
    //求最大值
    Array.prototype.maxima = function () {
        for (var i = 0,maxValue = Number.MIN_VALUE;i<this.length;i++)
            parseInt(this[i]) > maxValue && (maxValue = this[i]);
            return maxValue;
    }

    var arr = [1,21,3,4,22,45,6,7,32];
    alert(arr.join("+") + "=" + arr.sum()); //和：141
    alert(arr.join("|") + "中, 最大的数是:" + arr.maxima()); //最大数：45
</script>
</body>
</html>